//
//  SettingDealPassword.m
//  DaoZiJinFu
//
//  Created by woker on 16/6/27.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "SettingDealPassword.h"
#import "SettingBankInfo.h"

@interface SettingDealPassword ()

@end

@implementation SettingDealPassword

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTitleView:@"设置交易密码"];
    self.view.backgroundColor = BACKGROUND_COLOR;
    [self leftButton:nil];
    
    _nextBtn.layer.masksToBounds = YES;
    _nextBtn.layer.cornerRadius = BTN_RADIUS;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
  
}

- (IBAction)nextClick:(id)sender {
    if (![_pwdText.text isEqualToString:_confirmPwd.text]) {
        JSSHOW(@"两次密码不一致");
        return;
    }
    JSVIEWSHOW;
    DZRequestUtil *request = [[DZRequestUtil alloc] init];
    request.requestUrl = @"User/setTransactionPwd";
    request.params = @{@"pwd":_pwdText.text};
    [DZNetAPI request:request success:^(id response) {
        JSVIEWHIDE;
        DZResponse *model = [DZResponse mj_objectWithKeyValues:response];
        if (model.rt == 1) {
            JSSHOW(model.msg);
            [CommTools setUserInfo:response];
            if ([userValue(ISSETBANK) boolValue] == NO) {
                SettingBankInfo *setbankInfo = [[SettingBankInfo alloc] init];
                [self.navigationController pushViewController:setbankInfo animated:YES];
            } else {
                [self.navigationController popViewControllerAnimated:YES];
            }
        }else{
            JSSHOW(model.msg);
        }
    } failure:^(NSError *error) {
        JSVIEWHIDE;
        JSSHOW(LOAD_FAIL_TIP);
    }];
}

- (void)checkNextBtnUseabled {
    if (_pwdText.text.length && _confirmPwd.text.length) {
        _nextBtn.userInteractionEnabled = YES;
        _nextBtn.backgroundColor = BLUE_COLOR;
    } else {
        _nextBtn.userInteractionEnabled = NO;
        _nextBtn.backgroundColor = UNUSEABLECOLOR;
    }
}

- (IBAction)pwdChanged:(id)sender {
    [self checkNextBtnUseabled];
}

- (IBAction)confirmPwdChanged:(id)sender {
    [self checkNextBtnUseabled];
}

@end
